{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1ab2bab8",
   "metadata": {},
   "source": [
    "### 最常用的随机生成函数：\n",
    "- rand 0-1均匀分布的随机数组\n",
    "- randn 标准正太的随机数组\n",
    "- randint 随机整数组\n",
    "- choice 随机列表抽样"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "b13819c4",
   "metadata": {},
   "outputs": [],
   "source": [
    "## shuffle（x）\n",
    "- 将一个数组x随机打散排列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c741f037",
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d809574e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 0,  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12, 13, 14, 15, 16,\n",
       "       17, 18, 19])"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "one = np.arange(20)\n",
    "one"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "0d77cf04",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 2,  6, 12, 14,  7, 17, 19, 15,  4, 16, 10, 18,  0, 13,  1,  8,  5,\n",
       "        9, 11,  3])"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.shuffle(one)\n",
    "one"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "d1228dee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 5,  6,  7,  8,  9],\n",
       "       [10, 11, 12, 13, 14],\n",
       "       [15, 16, 17, 18, 19]])"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "two = np.arange(20).reshape(4,5)\n",
    "two"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93c465e1",
   "metadata": {},
   "source": [
    "#### 如果是多维数组，则只会在第一维度打散.只打乱了行数，列不会打散，数字顺序不变"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "3a20ee1e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[15, 16, 17, 18, 19],\n",
       "       [10, 11, 12, 13, 14],\n",
       "       [ 5,  6,  7,  8,  9],\n",
       "       [ 0,  1,  2,  3,  4]])"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.shuffle(two)\n",
    "two"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c05244fb",
   "metadata": {},
   "outputs": [],
   "source": [
    "# permutation（x）\n",
    "- 数字的全排列，全都重新打散"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "a366110b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([13,  3, 16, 12, 15,  5,  7,  0, 19,  8,  2, 10,  1,  9, 18, 11,  4,\n",
       "       14,  6, 17])"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.permutation(20)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "feb0867b",
   "metadata": {},
   "outputs": [],
   "source": [
    "two = np.arange(20).reshape(4,5)\n",
    "two"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "ea923872",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 5,  6,  7,  8,  9],\n",
       "       [ 0,  1,  2,  3,  4],\n",
       "       [15, 16, 17, 18, 19],\n",
       "       [10, 11, 12, 13, 14]])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.permutation(two)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "23ac730f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 0,  1,  2,  3,  4],\n",
       "       [ 5,  6,  7,  8,  9],\n",
       "       [10, 11, 12, 13, 14],\n",
       "       [15, 16, 17, 18, 19]])"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "two"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "16728a97",
   "metadata": {},
   "source": [
    "### shuffle会更改two，但是permutation不会改变two，只会返回一个新的copy（拷贝）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "af8723fc",
   "metadata": {},
   "outputs": [],
   "source": [
    "# normal([loc,scale,size])\n",
    "- 按照平均值和方差生成高斯分布的数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "689fef76",
   "metadata": {},
   "outputs": [],
   "source": [
    "# uniform([low,high,size])\n",
    "- 在low和high之间生成均匀分布的数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "17c65950",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([6.02062795, 5.98820802, 5.38673195, 5.36626384, 2.24306807,\n",
       "       3.31754175, 4.89465907, 4.14319155, 3.13405329, 1.76343272])"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.random.uniform(1,10,10)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "62fa6d3f",
   "metadata": {},
   "outputs": [],
   "source": [
    "# "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "09546dc7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ef802059",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "40fd0e3e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "962e10fe",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "1d8733d1",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "8e11117e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "695285e8",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a00ca3b7",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d82ecf73",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a71f3390",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "664afb92",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
